package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.utils.SnowflakeIdWorker;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FeatureType;
import com.ruoyi.system.service.IFeatureTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 特色类型Controller
 * 
 * @author ruoyi
 * @date 2024-01-04
 */
@RestController
@RequestMapping("/system/feature_type")
public class FeatureTypeController extends BaseController
{
    @Autowired
    private IFeatureTypeService featureTypeService;

    /**
     * 查询特色类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:feature_type:list')")
    @GetMapping("/list")
    public TableDataInfo list(FeatureType featureType)
    {
        startPage();
        List<FeatureType> list = featureTypeService.selectFeatureTypeList(featureType);
        return getDataTable(list);
    }

    /**
     * 导出特色类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:feature_type:export')")
    @Log(title = "特色类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeatureType featureType)
    {
        List<FeatureType> list = featureTypeService.selectFeatureTypeList(featureType);
        ExcelUtil<FeatureType> util = new ExcelUtil<FeatureType>(FeatureType.class);
        util.exportExcel(response, list, "特色类型数据");
    }

    /**
     * 获取特色类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:feature_type:query')")
    @GetMapping(value = "/{featureTypeId}")
    public AjaxResult getInfo(@PathVariable("featureTypeId") Long featureTypeId)
    {
        return success(featureTypeService.selectFeatureTypeByFeatureTypeId(featureTypeId));
    }

    /**
     * 新增特色类型
     */
    @PreAuthorize("@ss.hasPermi('system:feature_type:add')")
    @Log(title = "特色类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeatureType featureType)
    {
//        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(workerId, datacenterId);

        return toAjax(featureTypeService.insertFeatureType(featureType));
    }

    /**
     * 修改特色类型
     */
    @PreAuthorize("@ss.hasPermi('system:feature_type:edit')")
    @Log(title = "特色类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeatureType featureType)
    {
        return toAjax(featureTypeService.updateFeatureType(featureType));
    }

    /**
     * 删除特色类型
     */
    @PreAuthorize("@ss.hasPermi('system:feature_type:remove')")
    @Log(title = "特色类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{featureTypeIds}")
    public AjaxResult remove(@PathVariable Long[] featureTypeIds)
    {
        return toAjax(featureTypeService.deleteFeatureTypeByFeatureTypeIds(featureTypeIds));
    }
}
